package cn.com.bluemoon.bd.flink.pojo;

import cn.com.bluemoon.bd.flink.source.FixedTimeDataSource;
import cn.com.bluemoon.bd.utils.RegexUtils;
import com.google.common.collect.Sets;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Set;

@Data
public class HourMinute implements Serializable {
    private int hour;
    private int minute;

    public boolean equalTimePoint(int inHour, int inMinute) {
        if (this.hour == inHour && this.minute == inMinute) {
            return true;
        }

        return false;
    }

    public static Set<HourMinute> parse(String... hourMinutes) {
        Set<HourMinute> timePoints = Sets.newHashSet();

        for (String hourMinute : hourMinutes) {
            if (StringUtils.isBlank(hourMinute)) continue;

            if (RegexUtils.matches("\\s*\\d+\\s*:\\s*\\d+\\s*", hourMinute)) {
                String[] strArr = hourMinute.split(":");
                int hour = Integer.parseInt(strArr[0].trim());
                int minute = Integer.parseInt(strArr[1].trim());
                if (hour < 0 || hour > 23) continue;
                if (minute < 0 || minute > 59) continue;
                HourMinute point = new HourMinute();
                point.setHour(hour);
                point.setMinute(minute);
                timePoints.add(point);
            }
        }

        return timePoints;
    }
}
